<?php

namespace think;

use app\api\controller\WorkerServer;
use Workerman\Worker;
use Workerman\Lib\Timer;
require_once '../../vendor/workerman/workerman/Autoloader.php';
require '../../vendor/autoload.php';

// 执行HTTP应用并响应
$http = (new App())->http;
$response = $http->run();

$worker = new Worker('http://0.0.0.0:8585');
$worker->count = 2;
$worker->onWorkerStart = function($worker)
{
    // 只在id编号为0的进程上设置定时器，其它1、2、3号进程不设置定时器
    if($worker->id === 0)
    {
        Timer::add(30, function () {
            //当时间为凌晨2点时，执行
            if(date('H:i') == '02:00'){
                echo date('Y-m-d H:i:s').' execute start:';
                $workerServer=new WorkerServer();
                $workerServer->sendTimeOutMessage();
                echo ' execute end'."\r\n";
            }
        });
    }
};
// 运行worker
Worker::runAll();